package com.zhdl.common.protal;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.PageRequest;

import java.util.List;

/**
 * @author
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PageRes<T1> {

    /**
     * 总页面
     **/
    private int totalPage;

    /**
     * 当前页面
     **/
    private int currentPage;

    /**
     * 每页显示的条数
     **/
    private int pageSize;

    /**
     * 总记录数
     **/
    private long recordCount;

    /**
     * 查询的结果集
     */
    private List<T1> resList;


    public PageRes(PageRequest pageRequest, Integer count, List<T1> list) {

        this.totalPage = count % pageRequest.getPageSize() == 0 ? count / pageRequest.getPageSize() : count / pageRequest.getPageSize() + 1;
        this.currentPage = pageRequest.getPageNumber();
        this.pageSize = pageRequest.getPageSize();
        this.recordCount = count;
        this.resList = list;

    }

}
